home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 39 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.3 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: pardoej@lonnds.ml.com (Julian Pardoe LADS LDN X1428)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Name-mangling standard
  5. Date: 12 Jan 1996 12:56:44 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9601122037.AA15452@gstldnsrv2.lonnds.ml.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Fri, 12 Jan 1996 20:37:08 GMT
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMPbLJky4NqrwXLNJAQHb3gH9EGKoInGlPhn1B9dPdKhqhJGaTe7OaTpA
  13.     XESHyBSkNDzJuxPqRhpRPCPbr+wn8e16OMTDHLi1/+nLs6HzYYHYpA==
  14.     =nRob
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. In article <DL1pqE.KKq@infosoft.com>, jgalt@infosoft.com (John Galt) writes:
  18. --> > I certainly hope not!  Name mangling is a solution to passing type
  19. --> > information to 1950's linkers.  Once linkers become more sophisticated,
  20. --> > name mangling can disappear back into the slime from which it came.
  21. -->
  22. -->I beg to differ.  Name mangling serves several indispensible functions:
  23. -->
  24. -->1.  It makes it possible to have more than one function with the same name
  25. -->(differing in their argument lists).  To do this without mangling, the linker
  26. -->would have to see not just a function name, or even class::name, but a full
  27. -->_prototype_ for each function (omitting variable names and the result type).
  28.  
  29. ...but this is presumably just the kind of thing that the original author
  30. would expect his "more sophisticated" linkers to do!
  31.  
  32. -->2.  It allows the linker to do error checking.  Example:  Module A calls
  33. -->foo() in module B.  I change the definition of foo (and its argument list)
  34. -->but forget to change A.  Without name mangling, the program will simply crash
  35. -->(or do strange things because I've clobbered the stack...)
  36.  
  37. ...and this!
  38.  
  39. -->3.  When linking with other languages such as Pascal, it in effect checks that
  40. -->you told the C++ compiler to use the calling sequence for the language that
  41. -->the function you're calling is in.
  42.  
  43. ...and this!
  44.  
  45. -->For the same reason, I'm against the concept of "undefined behavior" in the C
  46. -->and C++ standards.  No program that has "undefined behavior" should compile.
  47.  
  48. It is not always possible for the compiler to check for undefined behaviour.
  49. I guess that
  50.     long *p = malloc (sizeof (int));
  51. is undefined behaviour but I don't think a compiler could easily
  52. check it.  And what about:
  53.     free (p);
  54.     *p = 27;
  55. If the two lines are in different source files the compiler really has
  56. very little chance.
  57.  
  58. It is possible to define a language where all errors are caught at
  59. compile time or run-time.  Such a language wouldn't be C .. or in
  60. the spirit of C.  We systems programmers need to do dodgy things
  61. from time to time and like C because it doesn't get in our way!
  62.  
  63. I believe that Modula-3 might be such a language, setting aside unsafe
  64. modules (which have to be explicitly marked as such): no "unchecked
  65. errors" can occur in a Modula-3 program.  But note that even here, we're
  66. relying on **runtime** checking, not compile time checking.  Code like
  67.     a : array [10] of integer;
  68.     i: integer;
  69.     read (i);
  70.     a[i] := 0;
  71. cannot be checked at compile time!
  72.  
  73. -- jP --
  74.  
  75.     
  76. ---
  77. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  78.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  79.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  80.